package gases.as3.testing
{
	import flash.display.DisplayObject;
	import flash.display.Loader;
	import flash.display.LoaderInfo;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.geom.Rectangle;
	import flash.net.URLRequest;
	import flash.text.TextField;
	import flash.utils.getTimer;
	
	import gases.as3.debug.DebugBase;
	import gases.as3.librarys.compnents.events.GButtonEvent;
	import gases.as3.librarys.compnents.resource.MacroResourceManagaers;
	import gases.as3.librarys.compnents.skin.SkinStylesMangaer;
	import gases.as3.librarys.compnents.skin.SkinTransform;
	import gases.as3.librarys.compnents.skin.data.BaseSkin;
	import gases.as3.librarys.compnents.skin.transform.TransformXML;
	import gases.as3.librarys.compnents.ui.basic.GLabel;
	import gases.as3.librarys.compnents.ui.control.GButton;
	import gases.as3.librarys.compnents.ui.control.GScrollBar;

	
	public class TestingGScroll extends Sprite
	{
		public function TestingGScroll()
		{
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			
			var loader:Loader = new Loader();
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
			loader.load(new URLRequest("assets/scroll.swf"));
		}
		
		private function onComplete(e:Event):void
		{
			
			var swf:DisplayObject = LoaderInfo(e.target).content as DisplayObject;
			MacroResourceManagaers.instance.UIResManager.setUISkinSwf(swf);
			var transform:SkinTransform = new SkinTransform();
			transform.setConfigTransform(new TransformXML());
			transform.resloveSkinConfig(xml);
			
			var upSkin:BaseSkin = SkinStylesMangaer.instance.getSkinData("scroll_up_btn") as BaseSkin;
			var downSkin:BaseSkin = SkinStylesMangaer.instance.getSkinData("scroll_down_btn") as BaseSkin;
			var scrollSkin:BaseSkin = SkinStylesMangaer.instance.getSkinData("scroll_btn") as BaseSkin;
			var scrollBgSkin:BaseSkin = SkinStylesMangaer.instance.getSkinData("scroll") as BaseSkin;
			
			
			var spr:Sprite = new Sprite();

			spr.graphics.beginFill(0xDF00DD);
			spr.graphics.drawRect(0,0,100,60);
			spr.graphics.endFill();
			spr.width = 160;
			spr.height = 1300;
			spr.x = 100;
			spr.y = 100;
			this.addChild(spr);
			var scrollBar:GScrollBar = new GScrollBar(160,300,spr,true,upSkin,downSkin,scrollSkin);
			scrollBar.skin = scrollBgSkin;
			scrollBar.x = 260;
			scrollBar.y = 100;
			this.addChild(scrollBar);
			
			var btn:GButton = new GButton();
			btn.x = 500;
			btn.skin = upSkin;
			this.addChild(btn);
			btn.addEventListener(GButtonEvent.BUTTON_CLICK,less);
			function less(e:GButtonEvent):void
			{
				spr.height = _num;
				scrollBar.updateScroll();
				_num += 50;
			}
		}
		
		private var _num:int = 50
		private var xml:XML = <root xmlns:skin="gases.compnents.ui.skin">
											<skin:button type="button" scale9_top="5" scale9_left="5" scale9_right="5" scale9_bottom="5" skinname="scroll_up_btn" width="60" height="20">
												<styles stylesName="button_down" resName="up_btn_down"/>
												<styles stylesName="button_up" resName="up_btn_up"/>
												<styles stylesName="button_over" resName="up_btn_over"/>
												<styles stylesName="button_out" resName="up_btn_out"/>
											</skin:button>
											<skin:button type="button" scale9_top="5" scale9_left="5" scale9_right="5" scale9_bottom="5" skinname="scroll_down_btn" width="60" height="20">
												<styles stylesName="button_down" resName="down_btn_down"/>
												<styles stylesName="button_up" resName="down_btn_up"/>
												<styles stylesName="button_over" resName="down_btn_over"/>
												<styles stylesName="button_out" resName="down_btn_out"/>
											</skin>
											<skin:button type="button" scale9_top="5" scale9_left="5" scale9_right="5" scale9_bottom="5" skinname="scroll_btn" width="60" height="20">
												<styles stylesName="button_down" resName="scroll_btn_down"/>
												<styles stylesName="button_up" resName="scroll_btn_up"/>
												<styles stylesName="button_over" resName="scroll_btn_over"/>
												<styles stylesName="button_out" resName="scroll_btn_out"/>
											</skin>
											<skin:scroll type="scroll" scale9_top="5" scale9_left="5" scale9_right="5" scale9_bottom="5" skinname="scroll" width="60" height="20">
												<styles stylesName="bg_scroll" resName="scroll_bg"/>
											</skin>
										</root>;
	}
}